package com.indusfo.spc.controller;

import com.indusfo.spc.pojo.MatFlow;
import com.indusfo.spc.pojo.OrderDete;
import com.indusfo.spc.pojo.OrderFlow;
import com.indusfo.spc.service.OrderFlowService;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author liub
 * @Date 2019/11/26 17:06
 * @Version 1.0
 */

@Controller
@RequestMapping("/service/orderFlow")
public class OrderFlowController {

    @Autowired
    private OrderFlowService orderFlowService;

    /**
     * 查询
     */
    @RequestMapping(value = "/queryOrderFlow")
    @ResponseBody
    public JSONObject queryOrderFlow(OrderFlow orderFlow) {
        JSONObject json = orderFlowService.queryOrderFlow(orderFlow);
        return json;
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/insertOrderFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject insertOrderFlow(OrderFlow orderFlow) {
        JSONObject json = orderFlowService.insertOrderFlow(orderFlow);
        return json;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/updateOrderFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject updateOrderFlow(OrderFlow orderFlow) {
        JSONObject json = orderFlowService.updateOrderFlow(orderFlow);
        return json;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/deleteOrderFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject deleteOrderFlow(@RequestParam("orderFlowIds") List<Integer> orderFlowIds, Integer dataState) {
        dataState = 2;
        JSONObject json = orderFlowService.deleteOrderFlow(orderFlowIds, dataState);
        return json;
    }

    /**
     * 启停
     */
    @RequestMapping(value = "/definedOrderFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject definedOrderFlow(@RequestParam("orderFlowIds") List<Integer> orderFlowIds, Integer dataState) {
        JSONObject json = orderFlowService.deleteOrderFlow(orderFlowIds, dataState);
        return json;
    }


    /**
     * 保存流程工位
     */
    @RequestMapping(value = "/saveOrderStation", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveOrderStation(@RequestBody OrderFlow orderFlow) {
        JSONObject json = orderFlowService.saveOrderStation(orderFlow);
        return json;
    }

    @RequestMapping(value = "/copyOrderStation", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject copyOrderStation(@RequestBody OrderFlow orderFlow) {
        JSONObject json = orderFlowService.copyOrderStation(orderFlow);
        return json;
    }

    /**
     * 保存流程采集参数
     */
    @RequestMapping(value = "/saveOrderDete", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveOrderDete(@RequestBody OrderFlow orderFlow) {
        JSONObject json = orderFlowService.saveOrderDete(orderFlow);
        return json;
    }

    /**
     * 保存流程采集参数 复制
     */
    @RequestMapping(value = "/copyOrderDete", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject copyOrderDete(@RequestBody OrderFlow orderFlow) {
        JSONObject json = orderFlowService.copyOrderDete(orderFlow);
        return json;
    }
    /**
     * 保存流程物料
     */
    @RequestMapping(value = "/saveOrderBom", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveOrderBom(@RequestBody OrderFlow orderFlow) {
        JSONObject json = orderFlowService.saveOrderBom(orderFlow);
        return json;
    }
    /**
     * 保存流程物料 复制
     */
    @RequestMapping(value = "/copyOrderBom", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject copyOrderBom(@RequestBody OrderFlow orderFlow) {
        JSONObject json = orderFlowService.copyOrderBom(orderFlow);
        return json;
    }
    /**
     * 保存不良现象
     */
    @RequestMapping(value = "/saveOrderBadpheno", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveOrderBadpheno(@RequestBody OrderFlow orderFlow) {
        JSONObject json = orderFlowService.saveOrderBadpheno(orderFlow);
        return json;
    }
    /**
     * 保存不良现象 复制
     */
    @RequestMapping(value = "/copyOrderBadpheno", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject copyOrderBadpheno(@RequestBody OrderFlow orderFlow) {
        JSONObject json = orderFlowService.copyOrderBadpheno(orderFlow);
        return json;
    }
    /**
     * @Author 熊冰  产品流程导入任务单流程
     * @Date 2019/12/4 14:47
     */
    @RequestMapping(value = "/leadOrderFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject leadOrderFlow(Integer matVerId, Integer orderId) {
        JSONObject json = orderFlowService.leadOrderFlow(matVerId, orderId);
        return json;
    }

    /**
     * 级联删除工序流程关联的工位、采集参数、关键物料、不良现象
     */
    @RequestMapping(value = "/deleteCascadeOrderFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject deleteCascadeOrderFlow(@RequestParam("orderFlowIds") List<Integer> orderFlowIds, Integer dataState) {
        dataState = 2;
        try {
            return orderFlowService.deleteCascadeOrderFlow(orderFlowIds, dataState);
        } catch (Exception e) {
            e.printStackTrace();
            return JSONObject.build(JSONObject.ERROR, e.getMessage(), null);
        }
    }

    /**
     * 任务单流程维修下工序新增查询
     */
    @RequestMapping(value = "/queryListOrderFlowToInsert")
    @ResponseBody
    public JSONObject queryListOrderFlowToInsert(OrderFlow orderFlow) {
        JSONObject json = orderFlowService.queryListOrderFlowToInsert(orderFlow);
        return json;
    }
}
